<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品订单</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row>
        <!--工具条-->
        <el-form
          :inline="true"
          :model="searchfrom"
          class="toolbar"
          label-position="right"
          label-width="70px"
        >
          <el-row>
            <el-form-item label="手机号">
              <el-input v-model="searchfrom.queryString" maxlength="11"></el-input>
            </el-form-item>
            <el-form-item label="类型">
              <el-select
                v-model="selectTypeValue"
                placeholder="请选择"
                clearable
                @change="selectTypeChange"
              >
                <el-option
                  v-for="item in typeList"
                  :label="item.name"
                  :key="item.status"
                  :value="item.status"
                ></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="状态">
              <el-select v-model="selectValue" placeholder="请选择" clearable @change="selectChange">
                <el-option
                  v-for="item in statusLits"
                  :label="item.name"
                  :key="item.status"
                  :value="item.status"
                ></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label>
              <el-button @click="getQiYiOrderList" type="success" style="width: 170px">查询</el-button>
            </el-form-item>
          </el-row>
        </el-form>
      </el-row>

      <!-- <el-form-item label>
        <el-button @click="searchOrderList" type="success" style="width: 170px">查询</el-button>
      </el-form-item>-->

      <el-row>
        <el-table :data="gridData">
          <el-table-column type="index"></el-table-column>
          <el-table-column property="authName" label="姓名"></el-table-column>
          <el-table-column property="mobile" label="电话"></el-table-column>
          <el-table-column property="money" label="单价(CNY)"></el-table-column>
          <el-table-column property="nickName" label="昵称"></el-table-column>
          <!-- <el-table-column property="numbers" label="数量"></el-table-column> -->
          <el-table-column property="status" label="状态">
            <template slot-scope="scope">
              <span>{{getuserstatus(scope.row.isUsed)}}</span>
            </template>
          </el-table-column>
          <el-table-column property="useType" label="类型">
            <template slot-scope="scope">
              <span>{{scope.row.useType==1?'话费':scope.row.useType==2?'油卡':''}}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope" v-if="scope.row.isUsed == 3 && scope.row.useType==2">
              <el-button type="success" size="mini" @click="fahuo(scope.row.id)">发货</el-button>
              <!-- <el-button type="danger" size="mini" @click="open(scope.row.id)">已失效</el-button> -->
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="searchfrom.pageNo"
        :page-sizes="[2, 5, 10, 15]"
        :page-size="searchfrom.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
    <el-dialog title="修改为已发货" :visible.sync="dialogFormVisible">
      <el-form :model="editform">
        <el-form-item label="物流公司" :label-width="formLabelWidth">
          <el-input v-model="editform.courierCompany" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="快递单号" :label-width="formLabelWidth">
          <el-input v-model="editform.trackingNumber" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="editformsubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      editform: {
        courierCompany: "",
        trackingNumber: "",
        id: ""
        
      },
      dialogFormVisible: false,
      gridData: [],
      searchfrom: {
        pageNo: 1,
        pageSize: 10,
        queryType: -1,
        queryId: -1,
        queryString: ""
      },
      statusLits: [
        {
          status: -1,
          name: "全部"
        },
        {
          status: 0,
          name: "未使用"
        },
        {
          //   0(待支付),1(待发货),2(待收货),3(已收货),4(退货申请中),5(退货中)6退货完成7申诉中8申诉失败9申诉成功10已失效
          status: 1,
          name: "已使用"
        },
        {
          status: 2,
          name: "已赠送"
        },
        {
          status: 3,
          name: "待发货"
        },

        {
          status: 4,
          name: "已发货"
        },
        {
          status: 5,
          name: "已完成"
        }
      ],
      typeList: [
        {
          status: "",
          name: "全部"
        },
        {
          status: 1,
          name: "话费"
        },
        {
          status: 2,
          name: "油卡"
        }
      ],
      selectValue: "",
      selectTypeValue: "",
      total: ""
    };
  },
  created() {
    this.getQiYiOrderList();
  },
  methods: {
    selectTypeChange(e) {
      this.searchfrom.queryId = e;
    },
    selectChange(e) {
      console.log(e);
      this.searchfrom.queryType = e;
    },
    getQiYiOrderList() {
      this.$http.post("/manage/seven/getCards", this.searchfrom).then(res => {
        console.log(res);
        if (res.data.status == 1) {
          this.gridData = res.data.data.list;
          this.total = res.data.data.total;
        } else {
          this.$message({
            type: "info",
            message: res.data.message
          });
        }
      });
    },
    fahuo(id) {
      this.$confirm("是否发货?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$http
            .post("/manage/seven/submitPush", { queryId: id })
            .then(res => {
              console.log(res);
              if (res.data.status == 1) {
                this.dialogFormVisible = false;
                this.$message({
                  type: "success",
                  message: "发货成功!"
                });
                this.getQiYiOrderList();
              } else {
                this.$message({
                  type: "info",
                  message: res.data.message
                });
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },

    editformsubmit() {
      this.$http
        .post("/manage/mall/editOrderStatusFaHuo", this.editform)
        .then(res => {
          console.log(res);
          if (res.data.status == 1) {
            this.dialogFormVisible = false;
            this.$message({
              type: "success",
              message: "修改成功!"
            });
            this.getcatelist();
          } else {
            this.$message({
              type: "info",
              message: "已取消"
            });
          }
        });
    },
    open(row) {
      this.$confirm("修改订单状态为，已失效, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$http
            .post("/manage/mall/editOrderStatusNo", {
              id: row
            })
            .then(res => {
              if (res.data.status == 1) {
                this.$message({
                  type: "success",
                  message: "修改成功!"
                });
                this.getcatelist();
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    edit(row) {
      this.editform.id = row;
      this.dialogFormVisible = true;
    },
    searchUserList() {
      this.getQiYiOrderList();
    },
    getuserstatus(row) {
      if (row == 0) {
        return "未使用";
      } else if (row == 1) {
        return "已使用";
      } else if (row == 2) {
        return "已赠送";
      } else if (row == 3) {
        return "待发货";
      } else if (row == 4) {
        return "已完成";
      } else if (row == 5) {
        return "已完成";
      }
    },
    getcatelist() {
      // if()
      this.$http
        .post("/manage/mall/getMallOrder", this.searchfrom)
        .then(res => {
          //   console.log(res)
          this.gridData = res.data.data.list;
          this.total = res.data.data.total;
          console.log(this.gridData);
        });
    },
    // 监听 pagesize 的变化
    handleSizeChange(newSize) {
      // 把最新的 pagesize 赋值给 this.queryinfo
      this.searchfrom.pageSize = newSize;
      this.getQiYiOrderList();
    },
    // 监听 页码值 的变化
    handleCurrentChange(newPageNum) {
      console.log(newPageNum);
      this.searchfrom.pageNo = newPageNum;
      this.getQiYiOrderList();
    }
    // POST /manage/mall/getMallOrder
  }
};
</script>
